package cn.edu.scau.dao;

import cn.edu.scau.entity.Nurse;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

public class NurseSqlProvider {

    public String insertSelective(Nurse record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("nurse");

        if (record.getNurseid() != null) {
            sql.VALUES("nurseID", "#{nurseid,jdbcType=INTEGER}");
        }

        if (record.getUserid() != null) {
            sql.VALUES("userId", "#{userid,jdbcType=INTEGER}");
        }

        if (record.getNursename() != null) {
            sql.VALUES("nursename", "#{nursename,jdbcType=VARCHAR}");
        }

        if (record.getNursesex() != null) {
            sql.VALUES("nurseSex", "#{nursesex,jdbcType=VARCHAR}");
        }

        if (record.getNurseage() != null) {
            sql.VALUES("nurseAge", "#{nurseage,jdbcType=INTEGER}");
        }

        if (record.getNurseuseflag() != null) {
            sql.VALUES("nurseUseflag", "#{nurseuseflag,jdbcType=BIT}");
        }

        return sql.toString();
    }

    public String updateByPrimaryKeySelective(Nurse record) {
        SQL sql = new SQL();
        sql.UPDATE("nurse");

        if (record.getUserid() != null) {
            sql.SET("userId = #{userid,jdbcType=INTEGER}");
        }

        if (record.getNursename() != null) {
            sql.SET("nursename = #{nursename,jdbcType=VARCHAR}");
        }

        if (record.getNursesex() != null) {
            sql.SET("nurseSex = #{nursesex,jdbcType=VARCHAR}");
        }

        if (record.getNurseage() != null) {
            sql.SET("nurseAge = #{nurseage,jdbcType=INTEGER}");
        }

        if (record.getNurseuseflag() != null) {
            sql.SET("nurseUseflag = #{nurseuseflag,jdbcType=BIT}");
        }

        sql.WHERE("nurseID = #{nurseid,jdbcType=INTEGER}");

        return sql.toString();
    }
    public String findByIdUseidName(Integer userId,Integer nurseID,String nursename){
        SQL sql = new SQL();
        sql.SELECT("nurseID, nursename, nurseSex, nurseAge, userId, nurseUseflag");
        sql.FROM("nurse");
        if(userId!=null){
            sql.WHERE(" userId like concat('%',#{userId},'%')");
        }
        if(nurseID!=null){
            sql.WHERE(" nurseID like concat('%',#{nurseID},'%')");
        }
        if(nursename!=null){
            sql.WHERE(" nursename like concat('%',#{nursename},'%')");
        }
        sql.WHERE(" nurseUseflag = true");
        return sql.toString();
    }
}